import {
	createRouter,
	createWebHistory
} from 'vue-router'
//导入组件
import LoginVue from '@/views/Login.vue'
import HomeVue from '@/views/Home.vue'
import AppointmentVue from '@/views/Appointment.vue'
import FeedbackVue from '@/views/Feedback.vue'
import MedicalRecordsVue from '@/views/MedicalRecords.vue'
import NewsVue from '@/views/News.vue'
import NewsDetailVue from '@/views/NewsDetail.vue'
import ProfileVue from '@/views/Profile.vue'

// 定义路由关系
// path  ：访问的路径    ；component:展示的组件
const routes = [
	{
		path: '/',
		component: LoginVue,
		meta: {
			title: '登录',
			keepAlive: false,//是否缓存
			requireAuth: false//是否需要身份验证
		}
	},
	{
		path: '/login',
		component: LoginVue,
		meta: {
			title: '登录'
		}
	},
	{
		path: '/home',
		component: HomeVue,
		redirect: '/news', //重定向，默认首页的访问页面
		children: [{
			path: '/news',
			component: NewsVue,
			meta: { keepAlive: false } // 确保禁用缓存
		},
		{
			path: '/records',
			component: MedicalRecordsVue
		},
		{
			path: '/appointment',
			component: AppointmentVue
		},

		{
			path: '/news/:id',
			name: 'NewsDetail',
			component: () => NewsDetailVue,
			props: true
		},
		{
			path: '/feedback',
			component: FeedbackVue
		},
		{
			path: '/profile',
			component: ProfileVue
		}
		]
	}
]

//创建路由器
const router = createRouter({
	//使用History模式
	history: createWebHistory(),
	//传递刚刚定义好的路由关系 routes
	routes: routes
});

//导出路由
export default router